﻿<!--/* 
* Copyright (c) 2009, The University of Texas at Austin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, 
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
*
* Neither the name of The University of Texas at Austin nor the names of its contributors may be 
* used to endorse or promote products derived from this software without specific prior written 
* permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/-->
<Window x:Class="BioBrowser.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:julmar="http://www.julmar.com/wpfhelpers"
    xmlns:ViewModels="clr-namespace:BioBrowser.ViewModels"
    xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    Title="CATUI 2.00.00 (BETA)" MinWidth="800" MinHeight="600"
    WindowStartupLocation="CenterScreen" ResizeMode="CanResize"
    DataContext="{julmar:ViewModelCreator ViewModelType={x:Type ViewModels:MainViewModel}}"
    julmar:LifetimeEvent.Close="{Binding NotifyCloseCommand}">
	<Window.Resources>
        
		<Style x:Key="DockedTabStyle" TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
			<Setter Property="HorizontalContentAlignment" Value="Stretch" />
			<Setter Property="VerticalContentAlignment" Value="Stretch" />
			<Setter Property="HeaderTemplate">
				<Setter.Value>
					<DataTemplate>
						<Grid HorizontalAlignment="Left" VerticalAlignment="Center">
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="Auto" />
								<ColumnDefinition />
								<ColumnDefinition Width="Auto" />
							</Grid.ColumnDefinitions>

							<ToggleButton Grid.Column="0" Margin="10,2" Style="{StaticResource TogglePin}" IsChecked="{Binding IsDocked}" />
							<Label Grid.Column="1" Content="{Binding Title}" VerticalAlignment="Center" HorizontalAlignment="Center" />
							<Button Grid.Column="2" Command="{Binding CloseCommand}" Margin="5" Style="{StaticResource CloseButton}" />
						</Grid>
					</DataTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</Window.Resources>

    <DockPanel>
        <Grid>
            <Grid.Resources>
                <Style x:Key="ContextMenuItemStyle" TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
                    <Setter Property="Header" Value="{Binding Text}"/>
                    <!--<Setter Property="Icon" Value="{Binding Icon}" />-->  
                    <Setter Property="ItemsSource" Value="{Binding Children}"/>
                    <Setter Property="Command" Value="{Binding Command}" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Text}" Value="{x:Null}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="MenuItem">
                                        <Separator />
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter> 
                        </DataTrigger> 
                    </Style.Triggers>
                </Style>

                <HierarchicalDataTemplate DataType="{x:Type ViewModels:BioCategoryViewModel}" ItemsSource="{Binding Children}">
                    <Border Background="Transparent">
                        <Interactivity:Interaction.Triggers>
                            <julmar:DoubleClickTrigger>
                                <julmar:InvokeCommand Command="{Binding DefaultCommand}" />
                            </julmar:DoubleClickTrigger>
                        </Interactivity:Interaction.Triggers>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding Image}" Width="20" Height="20" />
                            <Label Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding Header}" />
                        </StackPanel>
                        <Border.ContextMenu>
                            <ContextMenu ItemContainerStyle="{StaticResource ContextMenuItemStyle}" ItemsSource="{Binding MenuOptions}"  />
                        </Border.ContextMenu>
                    </Border>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type ViewModels:OpenBioDataViewModel}" ItemsSource="{Binding Children}">
                    <Border Background="Transparent">
                        <Interactivity:Interaction.Triggers>
                            <julmar:DoubleClickTrigger>
                                <julmar:InvokeCommand Command="{Binding DefaultCommand}" />
                            </julmar:DoubleClickTrigger>
                        </Interactivity:Interaction.Triggers>
                        <StackPanel Orientation="Horizontal">
                            <Ellipse x:Name="loadingBox" StrokeThickness="1" StrokeDashArray=".5,1" Width="20" Height="20" RenderTransformOrigin="0.5,0.5">
                                <Ellipse.Triggers>
                                    <EventTrigger RoutedEvent="Ellipse.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" RepeatBehavior="Forever">
                                                    <SplineDoubleKeyFrame KeyTime="00:00:02" Value="360"/>
                                                </DoubleAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Ellipse.Triggers>
                                <Ellipse.RenderTransform>
                                    <RotateTransform/>
                                </Ellipse.RenderTransform>
                                <Ellipse.Stroke>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="White" Offset="0"/>
                                        <GradientStop Color="#FFC9C9C9" Offset="0.5"/>
                                        <GradientStop Color="Black" Offset="1"/>
                                    </LinearGradientBrush>
                                </Ellipse.Stroke>
                            </Ellipse>
                            <Image x:Name="loadedImage" Visibility="Collapsed" Source="{Binding Image}" Width="20" Height="20" />
                            <Rectangle x:Name="unloadedImage" Visibility="Collapsed"  Width="20" Height="20" Fill="DarkGray" Stroke="Black" StrokeThickness="1" />
                            <Label x:Name="tb" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding Header}"  />
                        </StackPanel>
                        <Border.ContextMenu>
                            <ContextMenu ItemContainerStyle="{StaticResource ContextMenuItemStyle}" ItemsSource="{Binding MenuOptions}"  />
                        </Border.ContextMenu>
                    </Border>
                    <DataTemplate.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsLoading}" Value="False" />
                                <Condition Binding="{Binding IsLoaded}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="loadingBox" Property="Visibility" Value="Collapsed" />
                                <Setter TargetName="loadedImage" Property="Visibility" Value="Collapsed" />
                                <Setter TargetName="unloadedImage" Property="Visibility" Value="Visible" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                        <DataTrigger Binding="{Binding IsLoaded}" Value="True">
                            <Setter TargetName="loadingBox" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="loadedImage" Property="Visibility" Value="Visible" />
                            <Setter TargetName="unloadedImage" Property="Visibility" Value="Collapsed" />
                        </DataTrigger> 
                        <DataTrigger Binding="{Binding IsLoaded}" Value="False">
                            <Setter TargetName="tb" Property="Foreground" Value="LightGray" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type ViewModels:WorkspaceRootViewModel}" ItemsSource="{Binding Children}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding Image}" Width="20" Height="20" />
                        <Label Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding Header}" />
                        <StackPanel.ContextMenu>
                            <ContextMenu ItemContainerStyle="{StaticResource ContextMenuItemStyle}" ItemsSource="{Binding MenuOptions}"  />
                        </StackPanel.ContextMenu>
                    </StackPanel>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type ViewModels:WorkspaceViewModel}" ItemsSource="{Binding Categories}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding Image}" Width="20" Height="20" />
                        <Label Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding Header}" />
                        <StackPanel.ContextMenu>
                            <ContextMenu ItemContainerStyle="{StaticResource ContextMenuItemStyle}" ItemsSource="{Binding MenuOptions}"  />
                        </StackPanel.ContextMenu>
                    </StackPanel>
                </HierarchicalDataTemplate>

                <DataTemplate DataType="{x:Type ViewModels:OpenBioViewModel}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding Image}" Width="20" Height="20" />
                        <Label Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{Binding Header}" />
                        <StackPanel.ContextMenu>
                            <ContextMenu ItemContainerStyle="{StaticResource ContextMenuItemStyle}" ItemsSource="{Binding MenuOptions}"  />
                        </StackPanel.ContextMenu>
                    </StackPanel>
                </DataTemplate>

            </Grid.Resources>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            
            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <Border Padding="10,5" BorderThickness="0" Background="{DynamicResource ControlBackgroundBrush}">
                    <Label>Select a Data Source</Label>
                </Border>
                
                <TreeView Grid.Row="1" ItemsSource="{Binding Categories}" Margin="0">
                    <TreeView.ItemContainerStyle>
                        <Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                            <Setter Property="IsExpanded" Value="{Binding IsExpanded}" />
                            <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                        </Style>
                    </TreeView.ItemContainerStyle>
                </TreeView>
            </Grid>
            
            <GridSplitter Grid.Column="0"
                          HorizontalAlignment="Right" VerticalAlignment="Stretch"
                          Width="2" Background="Black" ResizeBehavior="CurrentAndNext" />

            <TabControl Grid.Column="1" ItemsSource="{Binding DockedViews}"
                        SelectedItem="{Binding SelectedView}" ItemContainerStyle="{DynamicResource DockedTabStyle}">
                
                <TabControl.ContentTemplate>
                    <DataTemplate>
                        <ContentControl Content="{Binding Visual}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    </DataTemplate>
                </TabControl.ContentTemplate>
            </TabControl>

        </Grid>
    </DockPanel>    
</Window>
